<?php

//exit(3333);
if(isset($_POST['typeid']))
{
	include_once 'config.php';
	$sql = "select * from product where find_in_set('{$_POST['typeid']}', type_id) and flag=1";
	$ret = mysql_query($sql);
	$output = array();
	while($row = mysql_fetch_array($ret))
	{
		$output[] = array('id' => $row['id'], 'name' => $row['name']);
	}
	if(count($output))
	{
		echo json_encode($output);
	}
	exit();
}

$curr_page =3;
include 'head.php';

?>
<link href="1.css" rel="stylesheet" type="text/css">
<style>
	.downTitle{
		background-color:#f1f1f1;
		width:895px;
		height:28px; 
		font-family:'宋体'; 
		font-size:12px; 
		color:#393939; 
		margin-top:25px; 
		margin-left:9px;
	}
	
	.downIcon{
			background:url(images/fx.jpg); 
			background-repeat:no-repeat;
			width:13px; 
			height:16px; 
			float:left; 
			margin:7px 0 0 7px;
	}
	
	.downList{
		width:895px;
		line-height:20px;
		font-size:12px;
		margin-left:9px;
	    clear:both;
	}
	.downItem{
		margin-top:15px; 
		width:895px;
	}
</style>
<script type="text/javascript">
  $(document).ready(function(){
	  $('#pro_type').change(function(){
		  if($(this).val() !="0")
		  {
			  $.post('download.php', {typeid:$(this).val()}, function(data){
				  $('#pro_id').find('option').slice(1).remove();
				  for(var i in data)
				  {
					  $('#pro_id').append($("<option value='"+data[i]['id']+"'>"+data[i]['name']+"</option>"));
				  }
			  },'json');
		  }else{
			  $('#pro_id').find('option').slice(1).remove();
	      }
	  });

	  $('#sb1').click(function(){
		  if($('#pro_id').val() == "0")
			  alert("请选择产品");
		  else
			  $('#form1').submit();
	  });
   });
</script>
<div id="ym1" style="background:#FFFFFF;">
				
		<div style="padding-bottom:15px;padding-top:1px;margin:0 auto;width:926px;">
					
			<div style="background: url(images/xw_nrt_5.jpg); padding-top:3px;padding-bottom:3px; margin-top:16px; height:36px; overflow: hidden; ">
								<h1 style="text-indent:16px;">相关下载</h1>
			</div>	
			<!-- 下载内容 -->
			<div style=" border:1px solid #c8c8c8;  margin-top:-1px; width:924px;padding-bottom:38px;border-top: none;">
			<form method="post" id="form1" action="" style="padding:25px 10px 0 10px;">
			    <?php 
			      $sql = "select * from pro_type where flag=1";
			      $pro_type = mysql_query($sql);
			    ?>
			    <select name="pro_type" id="pro_type">
			      <option value="0">选择产品类别</option>
			      <?php while($prow = mysql_fetch_array($pro_type)){?>
			      <option value="<?php echo $prow['id'];?>" <?php if(isset($_POST['pro_type']) && $_POST['pro_type'] == $prow['id']){echo "selected='selected'";}?>><?php echo $prow['name']?></option>
			      <?php }?>
			    </select>
			    <?php
			      if(isset($_POST['pro_type']))
			      {
			      	$sql = "select * from product where find_in_set({$_POST['pro_type']}, type_id)  and flag = 1";
			      	$pro_name = mysql_query($sql);
			      } 
			    ?>
			    <select name="pro_id" id="pro_id">
			      <option value="0">选择产品名称</option>
			      <?php while($pnrow = mysql_fetch_array($pro_name)){?>
			      <option value="<?php echo $pnrow['id']; ?>" <?php if(isset($_POST['pro_id']) && $_POST['pro_id'] == $pnrow['id']){echo "selected='selected'";}?>><?php echo $pnrow['name'];?></option>
			      <?php }?>
			    </select>
			    <input type="button" id="sb1"  style="background: url(images/search.gif) transparent no-repeat ; border:none; width:60px;height: 20px;" value=""/>
			    <a href="">显示全部</a>
			  </form>		
			  		
			  <?php 
					$sql = "select id,name,flag from download_type where flag =1";
					$result = mysql_query($sql);
					
					while($row = mysql_fetch_array($result))
					{
				?>
				
				<div class="downTitle">
					<div class="downIcon"></div>
					<span style="line-height:28px; float:left; margin-left:12px;"><?php echo $row['name']?></span>
					
<!--					<a href="" style="line-height:28px; float: right; margin-right:12px; color:#336699;text-decoration:none;">更多</a>-->
				</div>	
				<div class="downList">
				<?php 
					$sql = "select a.id as down_id,
									b.id as pro_id, 
									a.name as down_name,
									a.url as down_url,
									b.name as pro_name,
									b.model as pro_model,
									a.dates as down_dates,
									a.counts as down_counts
									from download as a inner join product as b on a.pro_id =b.id where a.flag =1 and a.type_ = ".$row['id'];
					if($_POST['pro_id'])
					  $sql .= " and b.id = {$_POST['pro_id']}";
					  
					$sql .= " order by a.dates desc";
					$result1 = mysql_query($sql);
				?>
				
					<div class="downItem" >
						<table width="100%">
						<tr>
						   <th width="30%">名称</th>
						   <th width="10%">产品型号</th>
						   <th width="30%">产品名称</th>
						   <th width="10%">更新日期</th>
						   <th width="10%">下载链接</th>
						   <th width="10%">下载次数</th>
						</tr>
			    <?php                    
			        while($row1 = mysql_fetch_array($result1))
                    {
                ?>
							<tr>
								<td style="width:180px;" align="center"><a style="text-decoration:none;color:black" href="downloaddetail.php?pro_id=<?php echo $row1['pro_id']?>&down_id=<?php echo $row1['down_id']?>" ><?php echo $row1['down_name']?></a></td>
								<td style="width:200px;" align="center"><a style="text-decoration:none;color:black" href="download1.php?id=<?php echo $row1['pro_id']?>" ><?php echo $row1['pro_model']?></a></td>
								<td style="width:60px" align="center"><a style="text-decoration:none;color:black" href="product_info.php?id=<?php echo $row1['pro_id']?>" ><?php echo $row1['pro_name'];?></a></td>
								<td  align="center"><?php echo $row1['down_dates']?></td>
								<td style="font-weight:bold;" align="center"><a style="color:#81a615;text-decoration:none;" href="<?php echo $row1['down_url']?>">点击下载</a></td>
								<td style="width:80px;text-align:center;" align="center"><?php echo $row1['down_counts'] ?>次</td>
							</tr>
				<?php
                    }
                ?>  
						</table>	
					</div>
				</div>		
				<?php
					}
				?>
									
				
				
			
				
				
			</div><!-- 下载内容 -->
				
	   </div>							
</div>
 						
 <?php include 'bottom.php';?>